﻿namespace Super.Admin.Utils.EventAggregator
{
    public interface IEventAggregator
    {
        /// <summary>
        /// 订阅事件
        /// </summary>
        /// <typeparam name="TEvent">订阅类型</typeparam>
        /// <param name="handler">订阅事件</param>
        /// <returns></returns>
        SubscriptionToken Subscribe<TEvent>(Action<TEvent> handler) where TEvent : class;
        /// <summary>
        /// 订阅带过滤条件的事件
        /// </summary>
        /// <typeparam name="TEvent">订阅类型</typeparam>
        /// <param name="handler">订阅事件</param>
        /// <param name="filter">过滤条件</param>
        /// <returns></returns>
        SubscriptionToken Subscribe<TEvent>(Action<TEvent> handler, Predicate<TEvent> filter) where TEvent : class;
        /// <summary>
        /// 订阅带执行选项的事件
        /// </summary>
        /// <typeparam name="TEvent">订阅类型</typeparam>
        /// <param name="handler">订阅事件</param>
        /// <param name="keepSubscriberReferenceAlive">是否强引用</param>
        /// <param name="dispatcherPriority">在UI线程的级别</param>
        /// <returns></returns>
        SubscriptionToken Subscribe<TEvent>(Action<TEvent> handler, bool keepSubscriberReferenceAlive = false, Control invokeControl = null) where TEvent : class;
        /// <summary>
        /// 取消订阅
        /// </summary>
        /// <typeparam name="TEvent">取消类型</typeparam>
        /// <param name="token">取消的Token</param>
        void Unsubscribe<TEvent>(SubscriptionToken token) where TEvent : class;
        /// <summary>
        /// 取消所有订阅
        /// </summary>
        void UnsubscribeAll();
        /// <summary>
        /// 发布事件
        /// </summary>
        /// <typeparam name="TEvent">发布类型</typeparam>
        /// <param name="event">发布参数</param>
        void Publish<TEvent>(TEvent @event) where TEvent : class;
        /// <summary>
        /// 发布事件并指定是否在UI线程执行
        /// </summary>
        /// <typeparam name="TEvent">发布类型</typeparam>
        /// <param name="event">发布参数</param>
        /// <param name="executeOnUIThread">是否在UI线程上执行</param>
        void Publish<TEvent>(TEvent @event, bool executeOnUIThread) where TEvent : class;
    }
}
